//
//  CardContainsView.swift
//  TanTan
//
//  Created by 于航 on 2024/9/15.
//

import SwiftUI

struct CardContainsView: View {
    @EnvironmentObject var appState : AppState
    @ObservedObject var viewModel : HomeViewModel
    @Namespace var nameSpace
    var card : CatCard
    var body: some View {
        if appState.isFullScreen {
            CardDetailView(nameSpace: nameSpace, catCard: card)
                .background(.white)
                .environmentObject(appState)
        } else {
            ZStack(alignment: .bottom) {
                CardView(catCard: card, swipeAction: viewModel.nextCatCard)
                    .matchedGeometryEffect(id: card.id, in: nameSpace)
                    .environmentObject(appState)
                if viewModel.hasMoreCard {
                    HStack {
                        ForEach(ButtonType.allCases) { type in
                            RoundButton(type: type, action: {
                                switch type {
                                case .back:
                                    debugPrint("Roll Back")
                                case .no:
                                    viewModel.nextCatCard()
                                case .heart:
                                    viewModel.nextCatCard()
                                case .star:
                                    debugPrint("Mark Star")
                                }
                            })
                            .frame(height: 45)
                        }
                    }
                    .padding(.bottom, 15)
                }
            }
            .padding(.horizontal, 20)
            .padding(.vertical, 20)
        }
    }
}

#Preview {
    CardContainsView(viewModel : HomeViewModel(), card: CatCard(name: "喵桑", age: 1, address: "小区花坛", category: "狮子猫", photos: ["Cat3", "Cat4"], info: "狮子猫是一种独特的猫品种，起源于中国山东临清，是波斯猫和中华田园鲁西狸猫杂交而成的品种。‌这种猫体型较大，略壮，脸宽而圆，嘴巴呈狐狸脸形状，耳朵短，直鼻梁，下巴强壮，眼睛多为双黄色、双蓝色或鸳鸯眼，四肢长短适中，爪子有长毛，毛长且大多为白色，也有花色毛。狮子猫性格活泼可爱，温顺聪明且粘人，能与陌生的同伴和谐相处。它们主要以鱼、虾、动物内脏和杂粮为食，需要定时、定量喂养，并添加适量的维生素和矿物质，同时给予足够的清水。狮子猫的繁殖性较差，每年一胎，每胎产仔2-3只。因其全身雪白、长毛和鸳鸯眼而被认为具有观赏价值。‌"))
        .environmentObject(AppState())
}
